//**********************************************************
//    File Name: FrmViewAppointments.cs
//    Author: Team Motif
//    Date Created : 04/13/2007
//    Current Owner: Team Motif 
//                                                                            
//    Purpose: 
//    To Display All Appointments in a week starting from 
//    a User specified View Date
//	  Copyright 2007
//**********************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Library;



namespace Elderhealth
{
    public partial class FrmViewAppointments : Form
    {
        /// <summary>
        /// Initialize the Form before displaying it
        /// </summary>
        public FrmViewAppointments()
        {
            InitializeComponent();
        }

        /// <summary>
        /// User clicks Exit Button
        /// </summary>
        private void ExitViewAppt_Click(object sender, EventArgs e)
        {
            Dispose(); 
        }

        /// <summary>
        /// Populating the View with Appointments in a particular date
        /// </summary>
        private void PopulateDataGridView(DataGridView DailyAppointments, DateTime startViewDate)
        {
            //Get all the appointments from DB with a given date and store them in array apptList
            ArrayList apptList = Library.Appointment.GetAppointmentByDate(startViewDate);
            Appointment apptInfo;
       
            //If appointment exist(s)
            if (apptList.Count > 0)
            {
                //Get each appt information and store it in apptInfo
                for (int i = 0; i < apptList.Count; i++)
                {
                    apptInfo = (Appointment)apptList[i];
                    String apptTime = apptInfo.GetBeginTime() + "-" + apptInfo.GetEndTime();
                    String apptDetails = "HCW: " + apptInfo.GetHcwName(apptInfo.GetHomeCareWorker()) + "  Client: " + apptInfo.GetClientName(apptInfo.GetClient());
                    //Display appt info in datagridview
                    DailyAppointments.Rows.Add(apptTime, apptDetails);
                }
            }
        }

        /// <summary>
        /// User clicks View Button and it will display the appointment 
        /// From the start date that the user picks up to 7 days
        /// </summary>
        private void ViewAppt_Click(object sender, EventArgs e)
        {
            //Get the value of the date that the user picks
            DateTime StartViewDate = dateTimePickerViewAppt.Value.Date;
            string[] DailyDates = new String[] { String.Empty, "1", "2", "3", "4", "5", "6", "7"};
            //store the date information as "MM/DD/YYYY" format
            DailyDates[0] = StartViewDate.ToString("d");       // result = "03/01/2007"
            //Day 1 Column
            viewApptGridViewDay1.Columns[0].HeaderText = DailyDates[0];
            viewApptGridViewDay1.Rows.Clear();
            //The function will get the particular date's appointments and display them
            PopulateDataGridView(viewApptGridViewDay1, StartViewDate);
      
            //Day 2 Column
            StartViewDate = dateTimePickerViewAppt.Value.AddDays(1);
            DailyDates[1] = StartViewDate.ToString("d");   
            viewApptGridViewDay2.Columns[0].HeaderText = DailyDates[1];
            viewApptGridViewDay2.Rows.Clear();
            PopulateDataGridView(viewApptGridViewDay2, StartViewDate);

            //Day 3 Column
            StartViewDate = dateTimePickerViewAppt.Value.AddDays(2);
            DailyDates[2] = StartViewDate.ToString("d");
            viewApptGridViewDay3.Columns[0].HeaderText = DailyDates[2];
            viewApptGridViewDay3.Rows.Clear();
            PopulateDataGridView(viewApptGridViewDay3, StartViewDate);

            //Day 4 Column
            StartViewDate = dateTimePickerViewAppt.Value.AddDays(3);
            DailyDates[3] = StartViewDate.ToString("d");
            viewApptGridViewDay4.Columns[0].HeaderText = DailyDates[3];
            viewApptGridViewDay4.Rows.Clear();
            PopulateDataGridView(viewApptGridViewDay4, StartViewDate);

            //Day 5 Column
            StartViewDate = dateTimePickerViewAppt.Value.AddDays(4);
            DailyDates[4] = StartViewDate.ToString("d");
            viewApptGridViewDay5.Columns[0].HeaderText = DailyDates[4];
            viewApptGridViewDay5.Rows.Clear();
            PopulateDataGridView(viewApptGridViewDay5, StartViewDate);

            //Day 6 Column
            StartViewDate = dateTimePickerViewAppt.Value.AddDays(5);
            DailyDates[5] = StartViewDate.ToString("d");
            viewApptGridViewDay6.Columns[0].HeaderText = DailyDates[5];
            viewApptGridViewDay6.Rows.Clear();
            PopulateDataGridView(viewApptGridViewDay6, StartViewDate);

            //Day 7 Column
            StartViewDate = dateTimePickerViewAppt.Value.AddDays(6);
            DailyDates[6] = StartViewDate.ToString("d");
            viewApptGridViewDay7.Columns[0].HeaderText = DailyDates[6];
            viewApptGridViewDay7.Rows.Clear();
            PopulateDataGridView(viewApptGridViewDay7, StartViewDate);
           
        }
    }
}